package com.qoq.test.chapter3;

/**
 * VM参数：-verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8 -XX:+UseSerialGC
 * -XX:PretenureSizeThreshold=3145728
 * PretenureSizeThreshold参数，指定大于该设置值的对象直接在老年代分配.
 * 避免在Eden区及两个Survivor区之间来回复制，产生大量的内存复制操作
 * 只对Serial和ParNew两款新生代收集器有效
 */
public class Direct2Old {
    private static final int _1MB = 1024 * 1024;

    public static void testPretenureSizeThreshold() {
        byte[] allocation1, allocation2, allocation3, allocation4;
        allocation1 = new byte[2 * _1MB];
        allocation2 = new byte[2 * _1MB];
        allocation3 = new byte[2 * _1MB];
        // 出现Minor GC
        allocation4 = new byte[4 * _1MB];
    }

    public static void main(String[] args) {
        testPretenureSizeThreshold();
    }
}
